package com.gc.controller.booksellerSevlet;

import com.gc.entity.BookSeller;
import com.gc.repository.BookSellerRepository;
import com.gc.repository.impl.BookSellerRepositoryImpl;
import com.gc.util.result.R;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "booksellerFind", value = "/booksellerFind" )
public class booksellerFind extends HttpServlet {
    BookSellerRepository BookSellerRepository = new BookSellerRepositoryImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        List<BookSeller> BookSellers = BookSellerRepository.FindAll();
        response.getWriter().write(gson.toJson(R.ok().data(BookSellers)));
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Gson gson = new Gson();
        List<BookSeller> BookSellers = BookSellerRepository.FindAll();
        response.getWriter().write(gson.toJson(R.ok().data(BookSellers)));
    }
}
